//
//  CourtViewController.m
//  云律司
//
//  Created by 韦淋 on 2017/6/19.
//  Copyright © 2017年 test. All rights reserved.
//

#import "CourtViewController.h"
@interface CourtViewController ()<UITableViewDelegate,UITableViewDataSource>


@property (nonatomic, strong) UITableView *courtTablewView;
@property (nonatomic, strong) NSMutableArray *dataSource;
@property (nonatomic, strong) UIButton *barAddButton;


@end

@implementation CourtViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.barTitleLable.text = @"法院开庭列表 ";
    self.dataSource = [NSMutableArray array];
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [self initUI];
    [self getData];
}
- (void)initUI{
    
    [self.view addSubview:self.courtTablewView];
    
    [self.view addSubview:self.barAddButton];
}
- (void)getData{
    [NetworkingManager getUrl:[NSString stringWithFormat:@"%@glid=%@",COURTINFO_URL,self.caseDetailDic[@"id"]] dic:nil Succeed:^(id responseData) {
        self.dataSource = responseData[@"result"];
        if (self.dataSource.count == 0) {
            [MBProgressHUD showSuccess:@"暂无更多数据"];
        }
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        NSLog(@"data = %@",self.dataSource);
        [self.courtTablewView reloadData];
        [self.courtTablewView.mj_header endRefreshing];
    } failure:^(NSError *error) {
        [MBProgressHUD showError:@"网络异常"];
        [MBProgressHUD hideHUDForView:self.view animated:YES];
    }];
}
- (void)loadNewData{
    [self.dataSource removeAllObjects];
    [self getData];
}
#pragma mark - Button Target
- (void)action_AddButton:(UIButton *)sender{
    AddInfoViewController *addVC = [[AddInfoViewController alloc] init];
    addVC.flag = self.log;
    addVC.caseDetailDic = self.caseDetailDic;
    
    [self.navigationController pushViewController:addVC animated:YES];
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 260;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CourtCell *cell = [tableView dequeueReusableCellWithIdentifier:@"courtCell" forIndexPath:indexPath];
    cell.titleLable.text = self.dataSource[indexPath.row][@"ah_number"];
    cell.judicialProcedure.text = [NSString stringWithFormat:@"审判程序： %@",self.dataSource[indexPath.row][@"spcx"]];
    cell.bailor.text = [NSString stringWithFormat:@"委托人： %@",self.dataSource[indexPath.row][@"wtr"]];
    cell.court.text = [NSString stringWithFormat:@"受理法院： %@",self.dataSource[indexPath.row][@"ft"]];
    cell.filingDate.text = [NSString stringWithFormat:@"立案时间： %@",self.dataSource[indexPath.row][@"ladate"]];
    cell.courtDate.text = [NSString stringWithFormat:@"开庭时间： %@",self.dataSource[indexPath.row][@"ktdate"]];
    cell.appealDate.text = [NSString stringWithFormat:@"上诉时间： %@",self.dataSource[indexPath.row][@"ssdate"]];
    cell.sentenceDate.text = [NSString stringWithFormat:@"宣判时间： %@",self.dataSource[indexPath.row][@"spdate"]];
    cell.remark.text = [NSString stringWithFormat:@"备注说明： %@",self.dataSource[indexPath.row][@"bzsm2"]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    EditInfoViewController *EIVC = [[EditInfoViewController alloc] init];
    EIVC.flag = self.log;
    EIVC.caseDetailDic = self.caseDetailDic;
    EIVC.listDetailDic = self.dataSource[indexPath.row];
    [self.navigationController pushViewController:EIVC animated:YES];
}
#pragma mark - Getter

- (UITableView *)courtTablewView{
    if (!_courtTablewView) {
        _courtTablewView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.bounds.size.width, self.view.bounds.size.height - 64) style:UITableViewStyleGrouped];
        _courtTablewView.backgroundColor = [UIColor clearColor];
        _courtTablewView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _courtTablewView.delegate = self;
        _courtTablewView.dataSource = self;
        _courtTablewView.estimatedRowHeight = 260;
        [_courtTablewView registerClass:[CourtCell class] forCellReuseIdentifier:@"courtCell"];
        _courtTablewView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
        
    }
    return _courtTablewView;
}
- (UIButton *)barAddButton{
    if (!_barAddButton) {
        _barAddButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _barAddButton.hidden = self.hideOrNot;
        _barAddButton.frame = CGRectMake(335, 30, 25, 25);
        [_barAddButton setBackgroundImage:[UIImage imageNamed:@"jiahao"] forState:UIControlStateNormal];
        [_barAddButton addTarget:self action:@selector(action_AddButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _barAddButton;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
